#include<bits/stdc++.h>
using namespace std;

long long a[200005],s[200005],f[200005];
void work() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        s[i]=s[i-1]+a[i]*(a[i]==a[i-1]);
    }
    memset(f,0,sizeof(f));
    for(int i=1;i<=n+1;i++) {
        for(int j=0;j<=i-2;j++) f[i]=max(f[i],f[j+1]+a[i]*(a[i]==a[j])+s[i-1]-s[j+1]);
    }
    cout<<f[n+1]<<"\n";
}
int main() {
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    while(t--) work();
    return 0;
}